/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.io.File;
/*    */ import java.util.Iterator;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class CheckDirectory
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 40 */     ZimbraSoapContext lc = getZimbraSoapContext(context);
/*    */     
/* 42 */     Server localServer = Provisioning.getInstance().getLocalServer();
/* 43 */     checkRight(lc, context, localServer, Rights.Admin.R_checkDirectoryOnFileSystem);
/*    */     
/* 45 */     Element response = lc.createElement(AdminConstants.CHECK_DIRECTORY_RESPONSE);
/*    */     
/* 47 */     Iterator<Element> iter = request.elementIterator("directory");
/* 48 */     while (iter.hasNext()) {
/* 49 */       Element dirReq = (Element)iter.next();
/* 50 */       String path = dirReq.getAttribute("path");
/* 51 */       boolean create = dirReq.getAttributeBool("create", false);
/* 52 */       File dir = new File(path);
/* 53 */       boolean exists = dir.exists();
/* 54 */       if ((!exists) && (create)) {
/* 55 */         dir.mkdirs();
/* 56 */         exists = dir.exists();
/*    */       }
/* 58 */       boolean isDirectory = false;
/* 59 */       boolean readable = false;
/* 60 */       boolean writable = false;
/* 61 */       if (exists) {
/* 62 */         isDirectory = dir.isDirectory();
/* 63 */         readable = dir.canRead();
/* 64 */         writable = dir.canWrite();
/*    */       }
/*    */       
/* 67 */       Element dirResp = response.addElement("directory");
/* 68 */       dirResp.addAttribute("path", path);
/* 69 */       dirResp.addAttribute("exists", exists);
/* 70 */       dirResp.addAttribute("isDirectory", isDirectory);
/* 71 */       dirResp.addAttribute("readable", readable);
/* 72 */       dirResp.addAttribute("writable", writable);
/*    */     }
/*    */     
/* 75 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 80 */     relatedRights.add(Rights.Admin.R_checkDirectoryOnFileSystem);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CheckDirectory.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */